package tech.summerly.weather.data

import android.net.Uri
import tech.summerly.weather.model.CameraMapConfiguration
import tech.summerly.weather.model.LiveWeatherSource
import tech.summerly.weather.model.Region
import tech.summerly.weather.util.LoggerLevel
import tech.summerly.weather.util.Position
import tech.summerly.weather.util.log

/**
 * 直播信号
 */
object LiveStreamRepository {


    private val uri: Uri
        get() {
//        Uri.fromFile(File(Environment.getExternalStorageDirectory(), "test.mp4"))
            return Uri.parse("rtmp://58.87.127.114/weather/dl")
        }


    private val dummyData = mapOf(
            "大连市" to listOf(
                    LiveWeatherSource("dl214124", "大连周水子机场", uri.toString(), Position(121.54625, 38.958766)),
                    LiveWeatherSource("dl2w1432134", "棒棰岛风景区", uri.toString(), Position(121.696282, 38.881571)),
                    LiveWeatherSource("dl14352351", "老铁山自然景区", uri.toString(), Position(121.202583, 38.733355))),
            "北京城区" to listOf(
                    LiveWeatherSource("bj21441", "北京首都国际机场", uri.toString(), Position(116.601362, 40.080193)),
                    LiveWeatherSource("bj2144123", "西城区", uri.toString(), Position(116.365842, 39.92187)),
                    LiveWeatherSource("bj21441123", "颐和园", uri.toString(), Position(116.271085, 39.990294))
            )
    )

    private val dummyMapRegion = mapOf(
            "大连市" to CameraMapConfiguration(Position(120.960818, 38.640738), Position(122.472812, 39.458725)),
            "北京城区" to CameraMapConfiguration(Position(116.003293, 39.713018), Position(116.736631, 40.143735))
    )


    /**
     * 是否支持当前地域的直播
     */
    fun isRegionSupport(region: Region): Boolean {
        return dummyMapRegion.containsKey(region.city)
    }

    /**
     * 获取指定区域的默认直播窗口
     */
    fun getDefaultLive(region: Region): LiveWeatherSource {
        val list = dummyData[region.city]
        if (list == null) {
            log(LoggerLevel.ERROR) { "$region" }
        }
        return list!![0]
    }

    /**
     * 获取指定区域的默认配置
     */
    fun getCameraMapConfiguration(region: Region): CameraMapConfiguration {
        val configuration = dummyMapRegion[region.city]
        if (configuration == null) {
            log(LoggerLevel.ERROR) { region }
        }
        return configuration!!
    }

    /**
     * 获取指定区域所有可用的直播窗口
     */
    fun getTotalAvailableLive(region: Region): List<LiveWeatherSource> {

        val list = dummyData[region.city]
        if (list == null) {
            log(LoggerLevel.ERROR) { "$region" }
        }
        return list!!
    }


}